//
//  ParamView.m
//  FKGW
//
//  Created by song ce on 2017/3/27.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "ParamView.h"
#import "UIView+Extend.h"
#import "PramaCell.h"
@implementation ParamView


- (void)awakeFromNib {
    [super awakeFromNib];
    self.dataSource = [NSMutableArray array];
    [self tableViewAndHeaderView];

}

-(void)setModel:(GoodsDetailModel *)model{
    _model = model;
    NSArray *parms = _model.proParam;
    if(self.dataSource.count){
        [self.dataSource removeAllObjects];
    }
    for(NSDictionary *dic in parms){
        PramaModel *model = [[PramaModel alloc]init];
        model.name = dic[@"name"];
        NSArray *vlues = dic[@"values"];
        NSDictionary *vdic = vlues.firstObject;
        model.value = vdic[@"value"];
        model.id = vdic[@"id"];
        [self.dataSource addObject:model];
    }
     [self.tableV reloadData];
}

- (void)tableViewAndHeaderView{
    //表视图
//    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, self.topLine.bottom, Main_Screen_Width, self.frame.size.height- self.topLine.height) style:UITableViewStylePlain];
    _tableV.showsVerticalScrollIndicator = NO;
    _tableV.backgroundColor = [UIColor whiteColor];
                               
    _tableV.delegate = self;
    _tableV.dataSource =self;
    [self addSubview:_tableV];
    _tableV.tableFooterView = [[UIView alloc]init];
    _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *ident=@"PramaCell";
     PramaCell*cell=[tableView dequeueReusableCellWithIdentifier:ident];
    if(cell==nil){
        cell=[[[NSBundle mainBundle]loadNibNamed:@"PramaCell" owner:self options:nil]lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    PramaModel *model = self.dataSource[indexPath.row];
    cell.model = model;
    return cell;
}

//关闭
- (IBAction)close:(id)sender {
      [[NSNotificationCenter defaultCenter]postNotificationName:@"PramaViewClose" object:nil];

}

@end
